package com.example.missingpersons;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * @Author: 小宇
 * @CreateTime: 2023/8/9 16:40
 */
public class AutoGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/missing_person?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8", "root", "3553682z")
                .globalConfig(builder -> {
                    builder.author("张芸博") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("Y://auto/"); // 指定输出目录
                })
                .templateConfig(builder -> {
                     builder.entity("/templates/entity.java.vm")
                            .service("/templates/service.java.vm")
                            .serviceImpl("/templates/serviceImpl.java.vm")
                            .mapper("/templates/mapper.java.vm")
                            .mapperXml("/templates/mapper.xml.vm")
                            .controller("/templates/controller.java.vm");
                })
                .packageConfig(builder -> {
                    builder.parent("com.example.missingpersons") // 设置父包名
                            .mapper("mapper")
                            .entity("entity")
                            .service("service")
                            .serviceImpl("serviceImpl")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "Y://auto/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder
                            .addInclude() // 设置需要生成的表名
                            .entityBuilder()
                            .enableLombok() //Lombok注解
                            .mapperBuilder()
                            .enableMapperAnnotation()//Mapper注解
                            .controllerBuilder()
                            .enableRestStyle()//@ResetController
                            .enableHyphenStyle();//驼峰式命名
                })
                .execute();
    }
}
